// @ts-nocheck
import Vue from "vue";

/**
 * Bind after-leave event for vue instance. Make sure after-leave is called in any browsers.
 *
 * @param {Vue} instance Vue instance.
 * @param {Function} callback callback of after-leave event
 * @param {Number} speed the speed of transition, default value is 300ms
 * @param {Boolean} once weather bind after-leave once. default value is false.
 */
export default function afterLeave(instance: Vue, callback: Function, speed: number = 300, once: boolean = false) {
  if (!instance || !callback) throw new Error('instance & callback is required');
  let called = false;
  const afterLeaveCallback = function () {
    if (called) return;
    called = true;
    if (callback) {
      callback.apply(null, arguments);
    }
  };
  if (once) {
    instance.$once('after-leave', afterLeaveCallback);
  } else {
    instance.$on('after-leave', afterLeaveCallback);
  }
  setTimeout(() => {
    afterLeaveCallback();
  }, speed + 100);
};
/**
 这个是element的工具，功能是离开这个组件以后执行对应的操作
 对于全局Vue.extend渲染的组件进行移除就很好用

 import afterLeave from 'element-ui/src/utils/after-leave'


 afterLeave(this, _ => {
                childPro.$destroy();
              }, 300);
 */
